package com.yangtzeu.jwc.business;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;

public class NewsListParser extends BaseParser {
    public Document doc;
    public List<NewsParser> newses;
    public String catalog;

    public NewsListParser() {
        super();
    }

    public NewsListParser(String path, String catalog) {
        super(path);
        this.catalog = catalog;
    }

    @Override
    public BaseParser startParse(ParserListener listener, boolean fromCache) {
        try {
            doc = parse(path, fromCache);
            Elements lis = doc.select("#list_r ul li");
            newses = new ArrayList<NewsParser>();
            NewsParser news;
            for (Element e : lis) {
                news = new NewsParser(e.select("a").get(0).attr("href"), this.catalog, e.select("a").get(0).text(), e.select("span").get(0).text());
                newses.add(news);
            }
            listener.finish();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
            listener.failed();
        }
        return this;
    }

}
